package blueBridge;

import java.util.Scanner;

public class Main2191 {
    
    int n;
    int m;
    int[] originNum;
    int[] maxNum;
    

    
    
    


    private Main2191(int n, int m, int[] originNum, int[] maxNum) {
        super();
        this.n = n;
        this.m = m;
        this.originNum = originNum;
        this.maxNum = maxNum;
    }


    private int getMaxGive() {
        int result = binaryFind();
        return result;
    }





    private int binaryFind() {
        int begin = 0;
        int end = 2 * n + m;
        int result = 0;
        while (begin < end) {
            int mid = (begin + end) / 2;
            if (check(mid) == 0) {
                result = mid;
                begin = mid + 1;
            } else {
                end = mid;
            }
        }
        return result;
    }


    private int check(int mid) {
        
        return 0;
    }


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] originNum = new int[n];
        int[] maxNum = new int[n];
        for (int i = 0; i < n; i++) {
            originNum[i] = scan.nextInt();
        }
        for (int i = 0; i < n; i++) {
            maxNum[i] = scan.nextInt();
        }
        Main2191 main = new Main2191(n, m, originNum, maxNum);
        System.out.println(main.getMaxGive());
    }







    
}
